<%@page import="com.wanmait.shoppingsys.vo.Specialty"%>
<%@page import="java.util.List"%>
<%@page import="com.wanmait.shoppingsys.util.ShopCar"%>
<%@page import="com.wanmait.shoppingsys.vo.UserInfo"%>
<%@page import="java.util.List"%>
<%@page import="com.wanmait.shoppingsys.vo.Specialty"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.wanmait.shoppingsys.util.ShopCar"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <% String path = request.getServletContext().getContextPath(); %>
    <jsp:include page="/inc/header.jsp"></jsp:include>

<div class="search_bar clearfix">
		<a href="<%=path %>/index.jsp" class="logo fl"><img src="<%=path %>/images/logo.png"></a>
		<form class="search_con fl" action="<%=path %>/SpecialtyController?action=serach" method="post">
			<input type="text" class="input_text fl" name="serach_produit" placeholder="搜索商品">
			<input type="submit" class="input_btn fr" name="serach" value="搜索">
		</form>
	
		<div class="guest_cart fr">
			<a href="<%=path %>/order/index.jsp" class="cart_name fl">我的购物车</a>
			<%ShopCar shopCar = (ShopCar)session.getAttribute("shopCar");
			UserInfo userinfo = (UserInfo)session.getAttribute("userinfo");
			if(userinfo==null){%>
			<div class="goods_count fl" id="show_count">0</div>
			<%}else{if(shopCar==null){%>
			<div class="goods_count fl" id="show_count">0</div>
			<%}else{ %>
			<div class="goods_count fl" id="show_count"><%=shopCar.getTotalNumber() %></div>
			<%} %>
			<%} %>
			
		</div>
</div>
	<% 
	if(userinfo==null){
	%>
	<div class="sorry"><em>对不起，您还没有登录！</em></div>
	<%}else{%>
	
	<div class="total_count">您的购物车清单
	<a id="clear" style="float:right;list-style:none;color:red;">清空购物车</a>		
	</div>	
	<ul class="cart_list_th clearfix">
		<li class="col01">商品名称</li>
		<li class="col02">商品单位</li>
		<li class="col03">商品价格</li>
		<li class="col04">数量</li>
		<li class="col05">小计</li>
		<li class="col06">操作</li>
	</ul>
<section class="qingkong">	
	<%
	if(shopCar!=null){
	List<Specialty> specialtys = shopCar.getSpecialtys();
	for(int i=0;i<specialtys.size();i++)
		{
			Specialty specialty = specialtys.get(i);
	%>
		<ul class="cart_list_td clearfix" >
		<li class="col01"><input type="checkbox" class="danxuan" checked></li>
		<li class="col02"><img src="<%=path %>/upload/goods/<%=specialty.getPic() %>"></li>
		<li class="col03"><%=specialty.getName() %><br><em><%=specialty.getPrice() %>/500g</em></li>
		<li class="col04">500g</li>
		<li class="col05"><%=specialty.getPrice() %></li>
		<li class="col06">
			<div class="num_add" data-id="<%=specialty.getId()%>">
				<a id="aaa" class="add fl">+</a>
				<input type="text" class="num_show fl" value="<%=specialty.getCount()%>" id="ccc">	
				<a id="bbb" class="minus fl">-</a>	
			</div>
		</li>
		<li class="col07" ><span id="ddd"><%=specialty.getCount()%></span>*<%=specialty.getPrice() %>元</li>
		<li class="col08"><a href="<%=path %>/ShopCarController?action=delete&id=<%=specialty.getId()%>">删除</a></li>
		</ul>
			<%
			if(i==specialtys.size()-1)
			{
			%>
			<ul class="settlements">
			<li class="col01"><input type="checkbox" class="duoxuan" checked></li>
			<li class="col02">全选</li>
			<li class="col03">合计(不含运费)：<span>¥</span><em class="total"><%=shopCar.getTotalPrice() %></em><br>共计<b class="number"><%=shopCar.getTotalNumber() %></b>件商品</li>
			<li class="col04"><a href="<%=path %>/order/order.jsp">去结算</a></li>
			</ul>
		<%
		}
		%>		
		<%
		}
		%>
			
		<%
		}
		%>
	<% 	
	}
	%>
</section>
<jsp:include page="/inc/footer.jsp"></jsp:include>


<script type="text/javascript">

$(function(){
	
	$("a.minus").click(function(){
		//-
		var that = $(this).parent();
		var id = that.data("id");
		var url = "<%=path%>/ShopCarController?action=diffCount&id="+id;
		$.get(url,function(mes){
			//mes里面是返回当前书的购物车中的数量
			var values = mes.split(",");
			that.find("#ccc").attr("value",values[0]);

			that.parent().parent().find("#ddd").html(values[0]);
			$(".total").html(values[1]);
			$(".number").html(values[2]);
			$("#show_count").html(values[2]);
		});
	});
	
	$("a.add").click(function(){
		//+
		var that = $(this).parent();
		var id = that.data("id");
		//alert(id);
		var url = "<%=path%>/ShopCarController?action=addCount&id="+id;
		$.get(url,function(mes){
			//mes里面是返回当前书的购物车中的数量
			var values = mes.split(",");
			that.find("#ccc").attr("value",values[0]);
			that.parent().parent().find("#ddd").html(values[0]);
			$(".total").html(values[1]);
			$(".number").html(values[2]);
			$("#show_count").html(values[2]);
		});
	});
	

		$("#clear").click(function(){
			$.get("<%=path%>/ShopCarController?action=clear",function(mes){
				$(".qingkong").css("color","red")
				$(".qingkong").css("font-size","20")
				$(".qingkong").css("margin-left","500")
				$(".qingkong").css("margin-top","60")
				$(".qingkong  ").html("空空如也，赶紧去添加购物车吧！");
				$("#show_count").html(0);
			});
			
		});
})
			$(".duoxuan").click(function(){
			
				if(this.checked==true)
				{
				$(".danxuan").prop("checked",true)
				}
				else
				{
				$(".danxuan").prop("checked",false)
				}
			});
			
		
		













</script>
